time: 2021.3
# -*- coding: utf-8 -*-
# @Time    : 2021/4/9 18:46
# @Author  : luogan
# @Email   : 468640092@qq.com
# @File    : ip_test.py
# @Software: PyCharm.
import random   #(导入模块)
with open("ips.txt","w",encoding="utf-8") as f:
    for i in range(120000):
        num = "172.25.254."
        f.write(num+str(random.randint(0,255))+"\n") #random模块随机获取网段

num1 = num+str(random.randint(0,255))
with open("ips.txt","r+",encoding="utf-8") as f:
    p_dict={}
    for line in f:
        if line in p_dict:
            p_dict[line] += 1
        else:
            p_dict[line] = 1

# p_dict[key] key =ip 值

    sort_ip = sorted(p_dict.values(),reverse=True)
    for ip in sort_ip:
        if ip in sort_ip[0:10]:
            print(ip,num1)
        else:
            continue






